#include<iostream>
#include<cstring>
using namespace std;

int n, v, a[31] = {0}, dp[31][20001];

int main () {
    cin >> v >> n;
    for (int i=1; i<=n; i++) {
    	cin >> a[i];
	}
    
    // core code
    memset(dp, 0, sizeof(dp));
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=v; j++) {
            if (j >= a[i])
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i]] + a[i]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }

    cout << v-dp[n][v] << endl;

    return 0;
}
